// ## 2023/09/26 # 氕氘氚 # 重构 ##
// ## 2021/10/01 # 江东新风 # namespace的韩文改成英文 ##
// ## 2021/03/02 # 江东新风 # 将特殊地名争夺移入873 ##
// ## 2021/01/12 # 江东新风 # 修复特殊设施闪退bug ##
// ## 2021/01/11 # 江东新风 # 修复异族伤害来源的特殊建筑破坏 ##
// ## 2021/01/13 # 江东新风 # 修复特殊设施闪退bug2 ##
// ## 2021/01/05 # 江东新风 # 添加雷电时特殊建筑不被破坏 ##
// ## 2020/08/13 # 氕氘氚 # 23:40 ##
namespace LIGHTNING_DAMAGE
{
	//---------------------------------------------------------------------------------------
	const int 部队落雷伤害 = 2000;
	const int 建筑落雷伤害 = 800;
	//---------------------------------------------------------------------------------------

	class Main
	{
		Main()
		{
			pk::set_func(215, pk::func215_t(callback));
		}

		void callback(pk::damage_info& info, pk::unit@ attacker, pk::hex_object@ target, bool critical)
		{
			if (target.is_instance(pk::unit::type_id))
			{
				float scale = pk::has_member(attacker, 武将_张角) ? ch::randfloat(1, 1.3) : ch::randfloat(0.8, 1.2);
				info.troops_damage = int(部队落雷伤害 * scale);
				// 士气减少伤害的2%
				info.energy_damage = info.troops_damage / 50;
			}
			else
			{
				float scale = pk::has_member(attacker, 武将_张角) ? ch::randfloat(1, 1.3) : ch::randfloat(0.8, 1.2);
				info.hp_damage = int(建筑落雷伤害 * scale);
				
				pk::building@ building = pk::hex_object_to_building(target);
				if (building.facility == 시설_제방 and !building.completed)
					info.hp_damage = 0;
			}

			info.tactics = -1;
			info.src_pos = attacker.get_pos();
			info.dst_pos = target.get_pos();
		}
		
	}

	Main main;
}